home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
DOUBLEDE
/
ZOOM.C
< prev
Wrap
C/C++ Source or Header
|
1988-01-18
|
3KB
|
155 lines
#include "MacTypes.h"
#include "Quickdraw.h"
#include "WindowMgr.h"
#include "MemoryMgr.h"
/*******************************************************************
Loose translation of ZoomRects() from an early release
of the Apple Software Supplement.
*******************************************************************/
#define ONE 65536L
#define ZOOMSTEPS 16
Fixed fract;
int blend(i1,i2)
int i1,i2;
{
Fixed smallFix,bigFix,tempFix;
smallFix = ONE * i1;
bigFix = ONE * i2;
tempFix = FixMul(fract,bigFix)+FixMul(ONE-fract,smallFix);
return(FixRound(tempFix));
}
zoomrect(smallrect,bigrect,zoomup)
Rect *smallrect,*bigrect;
Boolean zoomup;
{
Fixed factor;
Rect rect1,rect2,rect3,rect4;
GrafPtr savePort,deskPort;
int i;
GetPort(&savePort);
OpenPort(deskPort = (GrafPtr)NewPtr(sizeof(GrafPort)));
InitPort(deskPort);
SetPort(deskPort);
PenPat(gray);
PenMode(notPatXor);
if (zoomup)
{
rect1 = *smallrect;
factor = FixRatio(6,5);
fract = FixRatio(541,10000);
}
else
{
rect1 = *bigrect;
factor = FixRatio(5,6);
fract = ONE;
}
rect2 = rect1;
rect3 = rect1;
FrameRect(&rect1);
for (i=1;i<=ZOOMSTEPS;i++)
{
rect4.left = blend(smallrect->left,bigrect->left);
rect4.right = blend(smallrect->right,bigrect->right);
rect4.top = blend(smallrect->top,bigrect->top);
rect4.bottom = blend(smallrect->bottom,bigrect->bottom);
FrameRect(&rect4);
FrameRect(&rect1);
rect1 = rect2;
rect2 = rect3;
rect3 = rect4;
fract = FixMul(fract,factor);
}
FrameRect(&rect1);
FrameRect(&rect2);
FrameRect(&rect3);
ClosePort(deskPort);
DisposPtr((Ptr)deskPort);
PenNormal();
SetPort(savePort);
}
/********************************************************************
ltog(r)
Rect *r;
Converts the Rect referenced by *r from local to global
coordinate system.
*******************************************************************/
ltog(r)
Rect *r;
{
Point p1,p2;
p1 = topLeft(*r);
p2 = botRight(*r);
LocalToGlobal(&p1);
LocalToGlobal(&p2);
Pt2Rect(p1,p2,r);
}
gtol(r)
Rect *r;
{
Point p1,p2;
p1 = topLeft(*r);
p2 = botRight(*r);
GlobalToLocal(&p1);
GlobalToLocal(&p2);
Pt2Rect(p1,p2,r);
}
/********************************************************************
zoomport(wind,up)
WindowPtr wind;
Boolean up;
Zooms the window referenced by "wind" either from an inivisible
state to a visible state, or vice versa. Pass TRUE in the "up"
Boolean parameter to zoom a window to open, an FALSE to zoom
it close. The WindowPtr must have already been created elsewhere,
and zooming the window invisible only hides the window, it does
not destroy the WindowPtr data.
********************************************************************/
zoomport(wind,up)
WindowPtr wind;
Boolean up;
{
Rect r1,r2,r3;
SetPort(wind);
SetRect(&r1,0,20,0,20);
r3 = wind->portRect;
r2 = r3;
InsetRect(&r2,(r3.right-r3.left+20)/2,(r3.bottom-r3.top+20)/2);
ltog(&r2);
ltog(&r3);
if (up)
{
zoomrect(&r1,&r2,TRUE);
zoomrect(&r2,&r3,TRUE);
ShowWindow(wind);
SetPort(wind);
}
else
{
HideWindow(wind);
zoomrect(&r2,&r3,FALSE);
zoomrect(&r1,&r2,FALSE);
}
}